package com.briup.day19;

public class Test_ThreadName {
    public static void main(String[] args) {
        //获取当前线程对象
        Thread thread = Thread.currentThread();
        System.out.println("线程对象: " + thread);
        //获取当前线程对象名称
//        String name = thread.getName();
//        System.out.println("线程名称: " + name);
        //1.设置名称
        thread.setName("主线程main");
        System.out.println("获取线程名称: " + thread.getName());//还没设置好
        System.out.println("*******************************");
        //2.创建匿名内部类
        Thread t1 = new Thread("子线程1") {
            public void run() {
               Thread th = Thread.currentThread();
                String name1 = th.getName();
                System.out.println("线程对象："+th);
                System.out.println("线程名称：" + name1);
            }
        };
        Thread t2 = new Thread("子线程2") {
            public void run() {
                Thread th = Thread.currentThread();
                String name2 = th.getName();
                System.out.println("线程对象："+th);
                System.out.println("线程名称：" + name2);
            }
        };
        t1.start();
        t2.start();
    }
}
